<?php
// Carico dati della segnalazione
$username = JRequest::getVar('username');
if($username) {
	$query = "SELECT * FROM #__fap_soci WHERE username='$username'";
	$database->setQuery( $query );
	$data = $database->loadAssoc();
	if($data) {
		
		// Normalizzo date
		$data["dateofborn"] = date("d/m/Y", strtotime($data["dateofborn"]));
		
		if($data["parentdateofborn"] != '0000-00-00') {
			$data["parentdateofborn"] = date("d/m/Y", strtotime($data["parentdateofborn"]));
		} else {
			$data["parentdateofborn"] = "";
		}
	?>

						<fieldset>
							
							<div class="pulizia"></div>
							<div class="separatore"></div>
							<h4>dati personali</h4>
							<p>
							<label>nome</label>
							<input type="text" class="text" name="name" id="name" value="<?php echo isset($data["name"]) ? $data["name"] : "" ?>"/>
							</p>

							<p class="secondo">
							<label>cognome</label>
							<input type="text" class="text" name="surname" id="surname" value="<?php echo isset($data["surname"]) ? $data["surname"] : "" ?>"/>
							</p>
							
							<p>
							<label>luogo di nascita</label>
							<input type="text" class="text" name="placeofborn" id="placeofborn" value="<?php echo isset($data["placeofborn"]) ? $data["placeofborn"] : "" ?>"/>
							</p>

							<p class="secondo">
							<label>data di nascita (gg/mm/aaaa)</label>
							<input type="text" class="text" name="dateofborn" id="dateofborn" value="<?php echo isset($data["dateofborn"]) ? $data["dateofborn"] : "" ?>"/>
							</p>
							
							<div class="pulizia"></div>
							<p class="minorenne">
								<a id="toggle-minorenni">se minorenni inserire i dati di uno dei genitori</a>
							</p>
							
							<fieldset id="minorenni">
								<legend>dati di un genitore</legend>
								<p>
								<label>nome</label>
								<input type="text" class="text" name="parentname" id="parentname" value="<?php echo isset($data["parentname"]) ? $data["parentname"] : "" ?>"/>
								</p>
	
								<p class="secondo">
								<label>cognome</label>
								<input type="text" class="text" name="parentsurname" id="parentsurname" value="<?php echo isset($data["parentsurname"]) ? $data["parentsurname"] : "" ?>"/>
								</p>
								
								<p>
								<label>luogo di nascita</label>
								<input type="text" class="text" name="parentplaceofborn" id="parentplaceofborn" value="<?php echo isset($data["parentplaceofborn"]) ? $data["parentplaceofborn"] : "" ?>"/>
								</p>
	
								<p class="secondo">
								<label>data di nascita (gg/mm/aaaa)</label>
								<input type="text" class="text" name="parentdateofborn" id="parentdateofborn" value="<?php echo isset($data["parentdateofborn"]) ? $data["parentdateofborn"] : "" ?>"/>
								</p>
							
							</fieldset>
							
							<p>
								<label>email</label>
								<input type="text" class="text" name="email" id="email" value="<?php echo isset($data["email"]) ? $data["email"] : "" ?>"/>
							</p>

							<p class="secondo">
								<label>telefono</label>
								<input type="text" class="text" name="phone" id="phone" value="<?php echo isset($data["phone"]) ? $data["phone"] : "" ?>"/>
							</p>

							<p>
								<label>indirizzo</label>
								<input type="text" class="text" name="address" id="address" value="<?php echo isset($data["address"]) ? $data["address"] : "" ?>"/>
							</p>

							<p class="secondo">
								<label>CAP</label>
								<input type="text" class="text" name="zip" id="zip" value="<?php echo isset($data["zip"]) ? $data["zip"] : "" ?>"/>
							</p>
														
							<p>
								<label>città</label>
								<input type="text" class="text" name="city" id="city" value="<?php echo isset($data["city"]) ? $data["city"] : "" ?>"/>
							</p>
							
							<p class="secondo">
								<label>socio presentatore</label>
								<input type="text" class="text" name="inviteby" id="inviteby" value="<?php echo isset($data["inviteby"]) ? $data["inviteby"] : "" ?>"/>
							</p>

							<div class="pulizia"></div>
							<div class="separatore"></div>
							
							<h4>scelglie di diventare</h4>

							<p class="tiposocio">
								<input type="radio" name="type" id="type-amico" value="A" <?php echo $data["type"] == 'A' ? "checked=\"checked\"" : "" ?>/> 
								<label for="type-amico">
									<strong>amico</strong>
									colui che si impegna a sostenere la Fondazione i suoi principi e le sue finalità, senza alcun impegno economico
								</label>
																
								<input type="radio" name="type" id="type-sostenitore" value="S" <?php echo $data["type"] == 'S' ? "checked=\"checked\"" : "" ?>/>
								<label for="type-sostenitore">
									<strong>sostenitore</strong>
									colui che sostiene anche economicamente la Fondazione con un contributo volontario
								</label>
							</p>
							
							<div class="pulizia"></div>
							<div class="separatore"></div>

							<input type="hidden" value="<?php echo $data["id"] ?>" name="id"/>
							<input type="hidden" value="1" name="confirmed"/>
							<input type="hidden" value="1" name="notified"/>
							<input type="hidden" name="username" id="username" value="<?php echo isset($data["username"]) ? $data["username"] : "" ?>"/>

							<p>
								<button type="submit" class="confirm">accetta adesione</button>
							</p>
														
						</fieldset>
	<?php
	} else {
		echo JText::_('ALERTNOTAUTH');
	}
	
} else {
	echo JText::_('ALERTNOTAUTH');
}
?>